<%@page import="com.baozun.model.TFriend"%>
<%@page import="com.baozun.util.items.SelectSet"%>
<%@page import="com.baozun.util.StringUtil"%>
<%@page import="com.baozun.model.TUser"%>
<%@page import="com.baozun.util.PageData"%>
<%@page import="com.baozun.util.CommonConst"%>
<%@page import="java.util.List"%>
<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<meta name="description" content="Static &amp; Dynamic Tables" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />

<!-- basic styles -->

<link href="../assets/css/bootstrap.min.css" rel="stylesheet" />
<link rel="stylesheet" href="../assets/css/font-awesome.min.css" />
<link rel="stylesheet" href="../assets/css/font.css" />

<link rel="stylesheet" href="../assets/css/ace.min.css" />
<link rel="stylesheet" href="../assets/css/ace-rtl.min.css" />
<link rel="stylesheet" href="../assets/css/ace-skins.min.css" />

<script src="../assets/js/ace-extra.min.js"></script>
<style>
.page-header{
	padding-top:1px;
	padding-bottom:2px;
}

.table thead tr{
	background: #307ecc;
	color: #ffffff;
}
</style>
</head>
<%
TUser user = (TUser)session.getAttribute(CommonConst.SESSION_USER);
String stUserId = user.getStUserId();
PageData<TFriend> infoList = (PageData<TFriend>)request.getAttribute(CommonConst.REQUEST_PAGE_DATA);
int currPage = (Integer) request.getAttribute("currentPage");
int pageSize = (Integer) request.getAttribute("pageSize");
%>
<body style="min-height: 500px;">
	<div class="page-content">
		<div class="page-header">
			<h5>
				好友列表
			</h5>
		</div>
		<button class="btn btn-sm btn-success" onclick="javascript:openDialog('friend_add','添加好友','400','400')"><i class="icon-plus"></i>添加</button>
		<!-- /.page-header -->
		<div class="row">
			<div class="col-xs-12">
				<!-- PAGE CONTENT BEGINS -->
				<div class="row">
					<div class="col-xs-12">
						<div class="table-responsive">
						
							<table id="sample-table-1"
								class="table table-striped table-bordered table-hover">
								<thead>
									<tr>
										<th class="center">姓名</th>
										<th class="center">备注</th>
										<th class="center">操作</th>
										<th class="center">姓名</th>
										<th class="center">备注</th>
										<th class="center">操作</th>
									</tr>
								</thead>
								<tbody>
								<%
								for(int index = 0,size = infoList.size();index < size ;index +=2){
								    TFriend friend1 = infoList.get(index);
								    TFriend friend2 = (index+1)<size ? infoList.get(index + 1) : null;
								    boolean isRequest1 = stUserId.equals(friend1.getStUserIdRequest());
								    boolean isRequest2 = stUserId.equals(friend1.getStUserIdRequest());
								%>
									<tr>
										<td class="center"><%=StringUtil.param2Html(isRequest1?friend1.getStNameResponse():friend1.getStNameRequest()) %></td>
										<td class="center" onclick="update(this,'<%=friend1.getStFriendId()%>')"><%=StringUtil.param2Html(isRequest1?friend1.getStRemarkResponse():friend1.getStRemarkRequest()) %></td>
										<td class="center" style="width:15%">
											<div>
												<button class="btn btn-xs btn-pink" title="开始聊天" onclick="startChat('<%=friend1.getStFriendId()%>','<%=isRequest1?friend1.getStUserIdResponse():friend1.getStUserIdRequest()%>')">
													<i class=" icon-comments-alt bigger-120"></i>
												</button>
												<button class="btn btn-xs btn-danger" onclick="deleteFriend('<%=friend1.getStFriendId()%>')">
													<i class="icon-trash bigger-120"></i>
												</button>
											</div>
										</td>
										<%if(friend2 != null){
										    %>
										<td class="center"><%=StringUtil.param2Html(isRequest2?friend2.getStNameResponse():friend2.getStNameRequest()) %></td>
										<td class="center" onclick="update(this,'<%=friend2.getStFriendId()%>')"><%=StringUtil.param2Html(isRequest2?friend2.getStRemarkResponse():friend2.getStRemarkRequest()) %></td>
										<td class="center" style="width:15%">
											<div>
												<button class="btn btn-xs btn-pink" title="开始聊天" onclick="startChat('<%=friend2.getStFriendId()%>','<%=isRequest2?friend2.getStUserIdResponse():friend2.getStUserIdRequest()%>')">
													<i class=" icon-comments-alt bigger-120"></i>
												</button>
												<button class="btn btn-xs btn-danger" onclick="deleteFriend('<%=friend2.getStFriendId()%>')">
													<i class="icon-trash bigger-120"></i>
												</button>
											</div>
										</td>
										<%} %>
									</tr>
									<%}%>
								</tbody>
							</table>
							<div align="center">
							<%@include file="../include/pagenumber.jsp" %>
							</div>
						</div>
						<!-- /.table-responsive -->
					</div>
					<!-- /span -->
				</div>
				<!-- /row -->
			</div>
			<!-- /.col -->
		</div>
		<!-- /.row -->
	</div>
	<!-- /.page-content -->
	<script type="text/javascript" src="../assets/js/jquery-2.0.3.min.js"></script>
<script type="text/javascript" src="../js/artDialog/artDialog.source.js?skin=default"></script>
<script type="text/javascript" src="../js/artDialog/plugins/iframeTools.source.js"></script>
<script type="text/javascript" src="../js/openDialog.js"></script>
<script type="text/javascript" src="../js/openDialogcustom.js"></script>
<script type="text/javascript">
$(document).ready(function(){
    window.iframeResize = function(){  
        var  dvalue = 0;  
       // if($.browser.safari){  
       //     dvalue = 67; 
       // }  
        parent.document.getElementById("friend_iframe").scrolling = "yes";  
        parent.document.getElementById("friend_iframe").height = "";  
        parent.document.getElementById("friend_iframe").style.height = "";  
        parent.document.getElementById("friend_iframe").height = document.body.scrollHeight + dvalue;  
      };
      if(window.iframeResize){  
          window.iframeResize();  
      }
      parent.iFrameHeight();
});
function pagechange(page){
	parent.document.friend_search_form.currentPage.value=page;
	process();
}

//刷新查询
function process(){
	parent.document.friend_search_form.submit();
}
//删除
function deleteFriend(id){
	if(confirm("确认删除该好友吗?")){
		$.ajax({
			url:'friend_delete',
			data:{stFriendId:id},
			dataType:"text",
			type:"post",
			success:function(data,status){
				if("right" == data){
					process();
				}else{
					alert("删除失败！");
				}
			}	
	});
	}
}
//修改备注名称
function update(td,stFriendId){
	//将该td中内容修改为input
	var stRemark = $(td).html();
	$(td).html("<input type=\"text\" class=\"col-xs-12\" name=\"stRemark\" value=\""+stRemark+"\" onblur=\"update_submit(this,'"+stFriendId+"')\"/>");
	$(td).attr("onclick","");
}

//修改备注提交
function update_submit(input,stFriendId){
	var stRemark = $(input).val();
	var td = $(input).parent();
	$.ajax({
		url:"friend_remark_update_submit",
		data:{stFriendId:stFriendId,stRemark:stRemark},
		dataType:"text",
		type:"post",
		success:function(data,status){
			
		}
	});
	td.html(stRemark);
	td.attr("onclick","update(this,'"+stFriendId+"')");
}

//开始聊天
function startChat(stFriendId,stUserIdTo){
	var width = window.screen.width;
	var height = window.screen.availHeight;
	var newScreenHeight = 400;
	var newScreenWidth = 600;
	window.open("../chat/chat_detail?stFriendId="+stFriendId+"&stUserIdTo="+stUserIdTo, "newwindow", "height="+newScreenHeight+", top="+(height-newScreenHeight)/2+", left="+(width-newScreenWidth)/2+", width="+newScreenWidth+",  toolbar=no, menubar=no, resizable=no, location=no, status=no");
}
</script>
</body>
</html>